package com.wizinno.android.urineflow.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.wizinno.android.urineflow.R;
import com.wizinno.android.urineflow.application.ExitApplication;
import com.wizinno.android.urineflow.constant.CommonControl;

public class PasswordActivity extends BaseActivity {

    private static final String PASSWORD = "admin";
    private static final String PASSWORD_ADMIN = "";

    private EditText et_password;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ExitApplication.getInstance().addActivity(this);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_password);

        et_password = findViewById(R.id.et_password);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 0 && resultCode == RESULT_OK) {
            setResult(RESULT_OK);
            super.onDestroy();
            this.finish();
        }
    }

    public void toHome(View view) {
        Intent intent = new Intent(PasswordActivity.this, MainActivity.class);
//        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }

    public void passwordConfirm(View view) {
        String password = et_password.getText().toString();
        if (PASSWORD.equals(password) || PASSWORD_ADMIN.equals(password)) {
            //管理员
            if (PASSWORD_ADMIN.equals(password)) {
                CommonControl.INSTANCE.isAdmin = true;
            } else {
                CommonControl.INSTANCE.isAdmin = false;
            }
            Intent intent = new Intent(PasswordActivity.this, SystemSettingActivity.class);
            startActivity(intent);
        } else {
            Toast.makeText(this, "密码错误，请重新输入", Toast.LENGTH_LONG).show();
        }
    }
}